CXX	      := g++
CXXFLAGS  := -fPIC -g -O3 -MMD -fno-stack-protector -D_FORTIFY_SOURCE=0
OBJDIR	  := build
LDFLAGS   := -fPIC -Wl,-Ttext-segment=0x600000
LDLIBS    := -lrt 

CLIENT_OBJ := $(OBJDIR)/client.o
SERVER_OBJ := $(OBJDIR)/server.o

$(OBJDIR)/%.o: %.c
	@mkdir -p $(@D)
	$(CXX) $(CXXFLAGS) -c $< -o $@ 

.PHONY: all clean

all: client server

client: $(CLIENT_OBJ)
	@mkdir -p $(@D)
	$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $(OBJDIR)/$@
	@cp $(OBJDIR)/$@ ./bin/.

server: $(SERVER_OBJ)
	@mkdir -p $(@D)
	$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $(OBJDIR)/$@
	@cp $(OBJDIR)/$@ ./bin/.
	
clean:
	rm -rf $(OBJDIR) ./bin/* 
	






	